#include "FishingJoyData.h"
#include "StaticData.h"
USING_NS_CC;
using namespace std;
FishingJoyData* FishingJoyData::_instance=0;
FishingJoyData::FishingJoyData()
{
}

FishingJoyData::~FishingJoyData()
{
}

FishingJoyData* FishingJoyData::getInstance()
{
	if(!_instance){
		static FishingJoyData gameData;
		gameData.init();
		_instance=&gameData;
	}
	return _instance;
}

bool FishingJoyData::init()
{
	CCUserDefault *user_default=CCUserDefault::sharedUserDefault();
	_isBeginner=user_default->getBoolForKey("beginner",true);
	if(_isBeginner){
		reset();
		flush();
		setIsBeginner(false);
	}else{
		_isBeginner=user_default->getBoolForKey("beginner");
		_soundVolume=user_default->getFloatForKey("sound");
		_musicVolume=user_default->getFloatForKey("music");
		_gold=user_default->getIntegerForKey("gold");
		user_default->purgeSharedUserDefault();
	}
	return true;
}

void FishingJoyData::flush()
{
	CCUserDefault *user_default=CCUserDefault::sharedUserDefault();
	user_default->setFloatForKey("sound",getSoundVolume());
	user_default->setBoolForKey("beginner",getIsBeginner());
	user_default->setIntegerForKey("gold",getGold());
	user_default->setFloatForKey("music",getMusicVolume());
	user_default->flush();
	user_default->purgeSharedUserDefault();
}

void FishingJoyData::reset()
{
	int gold=StaticData::getInstance()->intFromKey("default_gold");
	setGold(gold);
	setIsBeginner(true);
	setMusicVolume(1);
	setSoundVolume(1);
	flush();
}

void FishingJoyData::alterGold(int delta)
{
	_gold+=delta;
}
